import { get, post, put, del } from '@/utils/request'

// 用户相关的类型定义
export interface Permission {
  id: number
  label: string
  value: number
  children?: null | Permission[]
}

export interface PermissionQueryParams {
  parentId: number
}

export interface PermissionResponse {
  totalCount: number
  totalPages: number
  list: Permission[]
}

// API 响应类型
export interface ApiResponse<T> {
  code: number
  msg: string
  data: T
}

// 创建角色的参数类型
export interface CreatePermissionParams {
  id: number
  loginName: string
  password: string
  userName: string
  gender: boolean
  phone: string
  birthday: string
  isDel?: boolean
}

// 获取权限列表
export const reqPermisionList = (data: PermissionQueryParams) => {
  return get<ApiResponse<Permission[]>>(
    '/api/Permissions/GetMenuItemList',
    data
  )
}

// 添加权限
export const reqCreatePermission = (data: any) => {
  return post<ApiResponse<number>>('/api/Permissions/AddPermission', data)
}

// 获取权限某一项
export const reqPermission = (data: any) => {
  return get<ApiResponse<any>>(`/api/Permissions/GetPermissionItem`, data)
}

// 删除权限
export const reqDeletePermission = (id: number) => {
  return del<ApiResponse<number>>(`/api/Permissions/DelPermissionItem?id=${id}`)
}
//-----------------------------------------------------------
// 修改权限
export const reqUpdatePermission = (data: any) => {
  return put<ApiResponse<number>>('/api/Permissions/UpdatePermissionOk', data)
}

// 获取菜单列表
export const getMenuList = () => {
  return get('/api/Account/GetMenuItemsList')
}

// 根据用户ID获取菜单
export const getUserMenus = (userId: number) => {
  return get('/api/Account/GetMenuItemsList', { userId })
}
